<template>
	<view class="container" :style="'min-height:' +pageHei+';'">
		<view class="u-flex u-col-center u-row-center" style="height: 88rpx;background-color: #ffffff;padding: 0 20rpx;">
			<view>
				<u-icon @click="toBack()" name="arrow-left" size="20" bold></u-icon>
			</view>
			<view class="u-flex-1 u-flex u-row-center">
				<picker mode="date" style="display: flex;align-items: center;justify-content: center;width: 450rpx;"
					fields="month" @change="changeTime">
					<view class="right-box u-flex">
						<text style="font-size: 30rpx;">{{acDate}}</text>
						<u-icon name="arrow-down-fill" size="10"></u-icon>
					</view>
				</picker>
			</view>
		</view>
		<u-sticky bgColor="#fff">
			<u-tabs :list="tabList" :scrollable="false" @click="clickTab"></u-tabs>
		</u-sticky>
		<view class="data-all">
			<text class="data-text">总收入￥0.00</text>
			<text class="data-text">直推￥0.00</text>
			<text class="data-text">间推￥0.00</text>
		</view>
		<view class="bill-list">
			<view class="bill-item u-flex u-row-between" v-for="(item,index) in acList" :key="index">
				<view class="bill-info u-flex-col">
					<text class="bill-name">{{item.usrCraftsman && item.usrCraftsman.usrName}}</text>
					<text class="bill-time">{{$u.timeFormat(item.orderDate || Date.now(),'mm月dd日 hh:MM')}}</text>
				</view>
				<text class="bill-mon">+0.00</text>
			</view>
		</view>
		<my-empty tipText="数据为空" v-if="isEmpty" image="http://cdn.uviewui.com/uview/empty/data.png"></my-empty>
		<u-loadmore :status="status" v-else></u-loadmore>
		<my-auth-modal></my-auth-modal>
	</view>
</template>
<script>
	import {
		queryCompanyFirstLevel,
		queryCompanyTwoLevel,
		queryMyTeamTwoLevel,
		queryMyTeamFirstLevel,
		queryCompanyPage,
		queryMyTeamPage
	} from '@/common/api/auth.js'
	import {
		getToken,
		setToken
	} from '@/utils/token.js'
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	export default {
		data() {
			return {
				tabList: [{
					name: '直推',
				}, {
					name: '间推',
				}],
				pageHei: '100vh',
				acDate: '',
				acIndex: 0,
				acList: [],
				acIndex: 0,
				version: getToken('version'),
				isEmpty: false,
				status: 'loading'
			}
		},
		onLoad: function() {
			this.getNewList()
			this.acDate = this.$u.timeFormat(new Date(Date.now() || Date.now()), 'yyyy-mm')
			uni.getSystemInfo({
				success: (res) => {
					this.pageHei = res.windowHeight * 2 + 'rpx'
				}
			})
		},
		onNavigationBarButtonTap(e) {
			uni.$u.route({
				url: '/pages/meSub/myInvitation/invitaionBill',
			})
		},
		methods: {
			toBack() {
				uni.navigateBack({})
			},
			getNewList() {
				if (this.acIndex == 0) {
					this.getOrderOne()
				} else if (this.acIndex == 1) {
					this.getOrderTwo()
				}
				this.getOrderMoney()
			},
			setData(res, filter) {
				this.acList = duplicateRemoval(this.acList, res.data && res.data && res.data.rows || [], filter)
				this.allpage = res.data && res.data.total
				this.currPage < this.allpage ? this.status = 'loadmore' : this.status = 'nomore'
				this.isEmpty = this.acList.length == 0 ? true : false
			},
			//所有订单数据金额
			getOrderMoney() {
				let params = {
					orderTeamDate: this.acDate + '-01',
					sourceName: 'vipOrderPlatformProfit',
				}
				if (this.version == 1) {
					params['parentCraftsmanId'] = getToken('useNum')
					queryMyTeamPage(params).then(res => {
						if (res.statusCode == 200) {
							this.setData(res, 'orderDate')
						}
					})
				} else {
					params['parentCompanyId'] = getToken('useNum')
					queryCompanyPage(params).then(res => {
						if (res.statusCode == 200) {
							this.setData(res, 'orderDate')
						}
					})
				}
			},
			//直推订单
			getOrderOne() {
				let params = {
					orderTeamDate: this.acDate + '-01',
					sourceName: 'vipOrderPlatformProfit',
				}
				if (this.version == 1) {
					params['parentCraftsmanId'] = getToken('useNum')
					queryMyTeamFirstLevel(params).then(res => {
					})
				} else {
					params['parentCompanyId'] = getToken('useNum')
					queryCompanyFirstLevel(params).then(res => {
					})
				}
			},
			// 间推订单
			getOrderTwo() {
				let params = {
					orderTeamDate: this.acDate + '-01',
					sourceName: 'vipOrderPlatformProfit',
				}
				if (this.version == 1) {
					params['parentCraftsmanId'] = getToken('useNum')
					queryMyTeamTwoLevel(params).then(res => {
					})
				} else {
					params['parentCompanyId'] = getToken('useNum')
					queryCompanyTwoLevel(params).then(res => {
					})
				}
			},
			clickTab(data) {
			},
			changeTime(e) {
				this.acDate = e.target.value
				this.acList = []
				this.currPage = 1
				this.getNewList()
			},
			clickTab(data) {
				this.acIndex = data.index
				this.acList = []
				this.currPage = 1
				this.getNewList()
			}
		}
	}
</script>
<style lang="scss">
	.container {
		background-color: #F8F8F8;

		.data-all {
			text-align: center;
			line-height: 80rpx;
			margin-top: 88rpx;
			font-size: 30rpx;
			color: #666666;

			.data-text {
				margin: 0 20rpx;
			}
		}

		.bill-list {
			background-color: #FFFFFF;
			padding: 0rpx 24rpx;

			.bill-item {
				border-bottom: 1rpx solid #EEEEEE;

				.use-img {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}

				.bill-name {
					font-size: 32rpx;
					margin-top: 20rpx;
				}

				.bill-time {
					font-size: 24rpx;
					color: #666666;
					line-height: 60rpx;
				}

				.bill-mon {
					font-size: 32rpx;
					color: #3E8BF3;
					font-weight: bold;
				}
			}
		}
	}
</style>
